package com.blue.http.config;

import com.blue.http.annotation.Websocket;
import com.blue.http.annotation.WebsocketParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

import java.util.List;
import java.util.Map;

/**
 * 解析websocket controller => bean 映射
 *
 * @author zhengjin
 * @since 1.0 2018年12月03日
 */
public class WebsocketControllerPostProcessor implements BeanFactoryPostProcessor
{
	private static Logger logger = LoggerFactory.getLogger(WebsocketControllerPostProcessor.class);

	private List<String> packageList;

	public WebsocketControllerPostProcessor()
	{
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
	{
		WebsocketParser parser = WebsocketParser.getInstance();
		logger.info("初始化 Websocket 解析");
		Map<String, Object> beanMap = beanFactory.getBeansWithAnnotation(Websocket.class);
		for (Map.Entry<String, Object> entry : beanMap.entrySet())
		{
			Class<?> clazz = entry.getValue().getClass();
			parser.parse(clazz);
		}
	}
}
